from textService import *
import os
import os.path
import sys

parentDirName = os.path.basename(os.path.dirname(__file__))
userDir = os.path.join(os.path.expandvars("%APPDATA%"), 'PIME', parentDirName)
sys.path.append(userDir)
# print('parentDirName: {}, userDir:{}'.format(parentDirName, userDir))
# 导入实际的实现模块
from pime_impl import PimeImpl


class PimeService(TextService):
    def __init__(self, client):
        TextService.__init__(self, client)
        self.icon_dir = os.path.abspath(os.path.dirname(__file__))
        self.impl = PimeImpl(self)

    def onActivate(self):
        TextService.onActivate(self)
        # Windows 8 systray IME mode icon
        self.impl.onActivate()

    def onDeactivate(self):
        self.impl.onDeactivate()
        TextService.onDeactivate(self)
        self.removeButton("test-btn")

    def filterKeyDown(self, keyEvent):
        return self.impl.filterKeyDown(keyEvent)

    # methods that should be implemented by derived classes
    def onKeyDown(self, keyEvent):
        return self.impl.onKeyDown(keyEvent)

    def filterKeyUp(self, keyEvent):
        return self.impl.filterKeyUp(keyEvent)

    def onKeyUp(self, keyEvent):
        return self.impl.onKeyUp(keyEvent)

    def onPreservedKey(self, guid):
        return self.impl.onPreservedKey(guid)

    def onCommand(self, commandId, commandType):
        self.impl.onCommand(commandId, commandType)

    def onMenu(self, buttonId):
        return self.onMenu(buttonId)

    def onCompartmentChanged(self, guid):
        pass

    def onCompositionTerminated(self, forced):
        self.impl.onCompositionTerminated(forced)

    def onKeyboardStatusChanged(self, opened):
        self.impl.onKeyboardStatusChanged(opened)
